package com.cqndt.disaster.device.controller;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import javax.servlet.http.HttpServletRequest;
import com.cqndt.disaster.device.util.AjaxResult;
import com.cqndt.disaster.device.service.AppTabDeviceService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgb
 * @date 2020-9-1
 * @return 设备类型及数据曲线管理
 **/
@RestController
@RequestMapping("/api/v2/deviceType")
public class DeviceTypeController extends BaseController{

    @Autowired
    private AppTabDeviceService appTabDeviceService;
    /**
     * @param request
     * @return 设备类型统计
     **/
    @RequestMapping(value="/statistics",method=RequestMethod.POST)
    public AjaxResult deviceTypeStatistics(HttpServletRequest request){
        String userId = request.getHeader("id");
        List<Map<String,Object>> list = appTabDeviceService.selectDeviceTypeStatistics(userId);
        Integer num = appTabDeviceService.selectDeviceTypeStatisticsTotal(userId);
        Map<String,Object> map = new HashMap<>();
        map.put("totalCount",num);
        map.put("mapList",list);
        return entityResult(map, "获取成功");
    }
    /**
     * @param request
     * @param deviceTypeId 设备类型
     * @param projectName 项目名称
     * @param page 设备类型
     * @param limit
     * @return 根据设备类型项目统计
     **/
    @RequestMapping(value="/projectByDeviceType",method = RequestMethod.POST)
    public AjaxResult projectByDeviceType(HttpServletRequest request,
    		String deviceTypeId,String projectName,Integer page,Integer limit){
        String userId = request.getHeader("id");
        PageHelper.startPage(page, limit);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(appTabDeviceService.selectProjectByDeviceType(userId,deviceTypeId,projectName));
        //String userId = "2";
        Integer num = (int)pageInfo.getTotal();
        return pageResult(limit, page, num, pageInfo.getList());
    }
    /**
     * @param deviceTypeId 设备类型
     * @param projectId 项目id
     * @param page
     * @param limit
     * @return 根据设备类型和projectId查看监测点
     **/
    @RequestMapping(value="/projectByDeviceTypeAndId",method=RequestMethod.POST)
    public AjaxResult projectByDeviceTypeAndId(String deviceTypeId,
    		String projectId,Integer page,Integer limit){
        page = null==page?1:page;
        limit = null==limit?10:limit;
        PageHelper.startPage(null==page?1:page, null==limit?10:limit);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(appTabDeviceService.projectByDeviceTypeAndId(deviceTypeId,projectId));
        return pageResult(limit, page, (int)pageInfo.getTotal(), pageInfo.getList());
    }
    /**
     * @param deviceId 设备id
     * @return 获取设备对应的传感器
     **/
    @RequestMapping(value="/getSensorByDeviceId",method = RequestMethod.POST)
    public AjaxResult getSensorByDeviceId(String deviceId){
        return entityResult(appTabDeviceService.listTabSensor(deviceId), "获取成功");
    }
    /**
     * @param sensorType 传感器类型
     * @param type 今天:today, 三天：threeDay, 本周:week, 本月:month, 近三个月:3month
     * @param sensorNo 传感器编号
     * @return 数据曲线
     **/
    @RequestMapping(value="/monitorStatistics",method=RequestMethod.POST)
    public AjaxResult monitorStatistics(String sensorType,String type,String sensorNo){
    	List<Map<String,Object>> list=appTabDeviceService.monitorStatistics(sensorType,type,sensorNo);
        return entityResult(list,"获取成功");
    }
}